<?php
// 本类由系统自动生成，仅供测试用途
class BaseAction extends Action {

    protected $userid;
    protected $username;
    protected $userinfo;
    protected $menu;

    //管理员auth   {"1": [2, 3, 4 ], "5": [6, 7 ], "8": [9, 10 ], "11": [] }
    //联通人员auth {"1":[4],"5":[6,7],"8":[9]}
    //快递auth     {"5":[6,7],"8":[10]}
    function _initialize(){

        //检查登录验证
    	$this->checkSession();

        $this->userid = session('userid');
        $this->username = session('user');
        $this->userinfo = session('userinfo');

        //读取所有角色
        $roleid = $this->userinfo['roleid'];
        $roles = getRoleAuth();
        $menu = D('Auth')->initAuth($roles[$roleid]);
        $this->assign('menu',$menu);
//        var_dump($menu);
    }

    protected function checkSession()
    {
    	if(!session('userid')){
    		$this->redirect('Public/login');
    	}
    }
    protected function checkIsAdmin(){
        $isadmin = false;
        if($this->userinfo['roleid']==1){
            $isadmin = true;
        }else{
            $isadmin = false;
        }
        return $isadmin;
    }
    public function _success($msg = '',$uri=''){
    	C('LAYOUT_ON',FALSE);
    	$this->success($msg,$uri);
    }

    public function _error($msg = '',$uri=''){
    	C('LAYOUT_ON',FALSE);
    	$this->error($msg);
    }

    protected function upload()
    {
    	import("ORG.Net.UploadFile");
		 //导入上传类
		$upload = new UploadFile();
		 //设置上传文件大小
		$upload->maxSize = 3292200;
		 //设置上传文件类型
		$upload->allowExts = explode(',', 'jpg,gif,png,jpeg');
		 //设置附件上传目录
		$upload->savePath = './Uploads/';
		 //设置需要生成缩略图，仅对图像文件有效
		$upload->thumb = true;
		 // 设置引用图片类库包路径
		//$upload->imageClassPath = '@.ORG.Image';
		 //设置需要生成缩略图的文件后缀
		$upload->thumbPrefix = 'm_';  //生产2张缩略图
		 //设置缩略图最大宽度
		$upload->thumbMaxWidth = '400';
		 //设置缩略图最大高度
		$upload->thumbMaxHeight = '400';
		 //设置上传文件规则
		$upload->saveRule = 'uniqid';
		 //删除原图
		//$upload->thumbRemoveOrigin = true;
		 if (!$upload->upload()) {
		    //捕获上传异常
		    $this->error($upload->getErrorMsg());
		 } else {
		    //取得成功上传的文件信息
		    $uploadList = $upload->getUploadFileInfo();
		    /*import("@.ORG.Image");
		    //给m_缩略图添加水印, Image::water('原文件名','水印图片地址')
		    Image::water($uploadList[0]['savepath'] . 'm_' . $uploadList[0]['savename'], APP_PATH.'Tpl/Public/Images/logo.png');
		    $_POST['image'] = $uploadList[0]['savename'];*/
		    foreach ($uploadList as $key => $value) {
		    	$retUpload[] = '/Uploads/' . $value['savename'];
		    }
		    return $retUpload;
		}
    }
}